'use client'; import React, { useEffect, useMemo, useState } from 'react'; import clsx from 'clsx'; import { useLocalization } from '@akinon/next/hooks'; import { useGetCountriesQuery, useGetStoresQuery, useGetRetailStoreCitiesQuery } from '@akinon/next/data/client/address'; import { Select, Accordion, Button, Icon, SkeletonWrapper, Skeleton } from '@theme/components'; import { GoogleMap, LoadScriptNext, Marker } from '@react-google-maps/api'; import { useForm } from 'react-hook-form'; import { Image } from '@akinon/next/components/image'; type SelectOptionType = { label: string; value: string | number; }; export default function Stores() { const { t } = useLocalization(); const [selectedCityPk, setSelectedCityPk] = useState(null); const [center, setCenter] = useState({ lat: 39.1615254, lng: 35.0687716, zoom: 2 }); const { register, watch } = useForm(); const selectedCountry = watch('country'); const selectedCity = watch('city'); const { data: stores } = useGetStoresQuery(); const { data: country, isLoading: countryLoading } = useGetCountriesQuery(); const { data: city, isLoading: cityLoading } = useGetRetailStoreCitiesQuery( selectedCountry, { skip: !selectedCountry } ); const countryOptions = useMemo(() => { if (country) { const options: SelectOptionType[] = [ { label: t('common.stores.select_country'), value: '' } ]; options.push( ...country.results.map((item) => ({ label: item.name, value: item.pk })) ); return options; } return []; }, [country]); // eslint-disable-line react-hooks/exhaustive-deps const cityOptions = useMemo(() => { if (city) { const options: SelectOptionType[] = [ { label: t('common.stores.select_city'), value: '' } ]; options.push( ...city.results.map((item) => ({ label: item.name, value: item.pk })) ); return options; } return []; }, [city]); // eslint-disable-line react-hooks/exhaustive-deps const handleBackButtonClick = () => { setSelectedCityPk(null); setCenter({ lat: 39.1615254, lng: 35.0687716, zoom: 2 }); }; useEffect(() => { if (selectedCity) { setSelectedCityPk(Number(selectedCity)); } }, [selectedCity]); return (

{t('common.stores.title')}

{countryLoading && ( )} {country && ( )}
{city && (
{cityLoading && ( )} {city.results.map((city, index) => (
{selectedCityPk !== city.pk ? ( ) : ( )}
{stores && stores.results .filter((store) => store?.township?.city?.pk === city.pk) .map((store, index) => (
{store.address && (
T: {store.address}
)}
{store.township.city.name && ( {store.township.city.name} / )} {store.township.city.country.name && ( {store.township.city.country.name} )}
{store.phone_number && (
T: {store.phone_number}
)} {store.fax_phone_number && (
F: {store.fax_phone_number}
)} {store.image && ( {store.address} )}
{store.latitude && store.longitude && ( )}
))}
))}
)}
} > {stores && stores.results.map((store, index) => ( ))}
); }